package com.liuning.websocketdemo.pojo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/*
用来封装消息的工具类
 */
public class MessageUtils {

    public static String getMessage(boolean isSystem,String fromName,Object message) {
        try {
            ResultMessage result = new ResultMessage();
            result.setSystem(isSystem);
            result.setMessage(message);
            if (fromName != null) {
                result.setFromName(fromName);
            }
            ObjectMapper mapper = new ObjectMapper();
            //返回String类型
            return mapper.writeValueAsString(result);
        }catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
